Can someone explain to me why the following code gives an error (at least in 8.3).
Buffer buf = null
void writeToBuf(Buffer &refBuf, string writeStr)
{
if (null(refBuf))
{
refBuf = create()
refBuf = ""
}
refBuf += writeStr "\n"
}
writeToBuf(buf, "Test1")
writeToBuf(buf, "Test2")
print stringOf(buf)
-R-E- DXL: <Line:11> null buffer parameter was passed into argument position 1
Backtrace:
<Line:14>
-I- DXL: execution halted
void delete(Buffer &b)
SSloan - Fri Jun 11 16:47:01 EDT 2010 |
Re: Passing Buffer by reference That is &refBuf is a pointer to null, but this way null(refBuff) == false, since this pointer has some value, eg. 9213943... The question you'd like to ask is if the place where refBuf points has a value of null, so you'd need dereference operation. I assume you don't wan to initialize the buffer in the beginning, so a quick and dirty fix would be: Buffer buf = null void writeToBuf(Buffer &refBuf, string writeStr) { Buffer b = refBuf if ( null(b) ) { refBuf = create() } refBuf += writeStr "\n" } writeToBuf(buf, "Test1") writeToBuf(buf, "Test2") print stringOf(buf) I asked the same question in the thread: References, function declarations and "underscore types" (_* _x etc.) |
Re: Passing Buffer by reference Regiss - Mon Jun 14 12:06:16 EDT 2010 Buffer buf = null void writeToBuf(Buffer &refBuf, string writeStr) { Buffer b = refBuf if ( null(b) ) { refBuf = create() } refBuf += writeStr "\n" } writeToBuf(buf, "Test1") writeToBuf(buf, "Test2") print stringOf(buf) I asked the same question in the thread: References, function declarations and "underscore types" (_* _x etc.) if (null( (addr_ refBuf) Buffer) ) { ... } |
Re: Passing Buffer by reference Regiss - Mon Jun 14 12:10:52 EDT 2010
I like where you are going and I think I tried something similar. I couldn't get it to work though and I'm still getting the same error with your code. :-( Here is the code that I ran.
Buffer buf = null
void writeToBuf(Buffer &refBuf, string writeStr)
{
if (null( (addr_ refBuf) Buffer) )
{
refBuf = create()
}
refBuf += writeStr "\n"
}
writeToBuf(buf, "Test1")
writeToBuf(buf, "Test2")
print stringOf(buf)
-R-E- DXL: <Line:10> null buffer parameter was passed into argument position 1
Backtrace:
<Line:13>
-I- DXL: execution halted
|
Re: Passing Buffer by reference SSloan - Mon Jun 14 20:22:42 EDT 2010
I like where you are going and I think I tried something similar. I couldn't get it to work though and I'm still getting the same error with your code. :-( Here is the code that I ran.
Buffer buf = null
void writeToBuf(Buffer &refBuf, string writeStr)
{
if (null( (addr_ refBuf) Buffer) )
{
refBuf = create()
}
refBuf += writeStr "\n"
}
writeToBuf(buf, "Test1")
writeToBuf(buf, "Test2")
print stringOf(buf)
-R-E- DXL: <Line:10> null buffer parameter was passed into argument position 1
Backtrace:
<Line:13>
-I- DXL: execution halted
|
Re: Passing Buffer by reference SSloan - Mon Jun 14 20:24:58 EDT 2010 Buffer buf = create()
|